package com.tom.demo.common.esEntity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.ZonedDateTime;

/**
 * FieldType.Text会被分词 Keyword则不会被分词
 */
@Data
@Document(indexName = "sys_logs", shards = 5, replicas = 2)
@ApiModel(value = "日志")
public class SysLogDocIndex implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @ApiModelProperty(value = "id")
    private String id;

    @Field(type = FieldType.Text)
    @ApiModelProperty(value = "操作的模块")
    private String operaModel;


    @Field(type = FieldType.Text)
    @ApiModelProperty(value = "操作说明")
    private String operaDesc;

    @Field(type = FieldType.Keyword)
    @ApiModelProperty(value = "操作标识code")
    private String operaCode;

    @Field(type = FieldType.Keyword)
    @ApiModelProperty(value = "操作类型")
    private String operaType;


    @Field(type = FieldType.Keyword)
    @ApiModelProperty(value = "请求方式")
    private String requestMethod;

    @Field(type = FieldType.Text)
    @ApiModelProperty(value = "请求url")
    private String requestUrl;

    @Field(type = FieldType.Text)
    @ApiModelProperty(value = "请求ip")
    private String requestIp;

    @Field(type = FieldType.Boolean)
    @ApiModelProperty(value = "操作状态（true正常 false异常）")
    private Boolean operaStatus;

    @Field(type = FieldType.Integer)
    @ApiModelProperty(value = "执行消耗时间/s秒")
    private Integer operaCostTime;

    @Field(type = FieldType.Text)
    @ApiModelProperty(value = "操作人名称")
    private String operaNickName;

    @Field(type = FieldType.Keyword)
    @ApiModelProperty(value = "操作人id")
    private String operaUserId;

    @Field(type = FieldType.Date,format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "操作的日期")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") //用于后端返回给前端的格式
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") //用于后端返接收前端的日期格式
    private ZonedDateTime operaDateTime;

    @Field(type = FieldType.Keyword)
    @ApiModelProperty(value = "异常信息")
    private String exceptionMessage;

    @Field(type = FieldType.Keyword)
    @ApiModelProperty(value = "异常堆栈信息")
    private String exceptionStack;

    //该字段是搜索的关键子
    private String keyWord;

}